//
//  MMImageView.m
//  MemeMaker
//
//  Created by Phan Quang Ha on 8/10/13.
//  Copyright (c) 2013 soyo. All rights reserved.
//

#import "MMImageView.h"

@interface MMImageView ()
{
    UILabel *lbl;
}
@end

@implementation MMImageView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}
- (void)awakeFromNib
{
    [super awakeFromNib];
    
    lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 20)];
    lbl.font = [UIFont boldSystemFontOfSize:13];
    lbl.textColor = [UIColor blueColor];
    lbl.backgroundColor = [UIColor clearColor];
    lbl.textAlignment = NSTextAlignmentCenter;
    [self addSubview:lbl];
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
//- (void)drawRect:(CGRect)rect
//{
//    CGContextRef context = UIGraphicsGetCurrentContext();
//    if (self.image) {
//        CGSize imgSize = self.image.size;
//        
//        [self.image drawInRect:CGRectMake(0, 0, rect.size.width, imgSize.height * rect.size.width / imgSize.width)];
//        CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor);
//        if(!_isHiddenName)
//            [self.name drawInRect:CGRectMake(3, 0, 100, 20) withFont:[UIFont systemFontOfSize:13]];
//        
//        CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
//        CGPathRef path = CGPathCreateWithRect(rect, nil);
//        CGContextSetLineWidth(context, 1);
//        CGContextAddPath(context, path);
//        CGContextStrokePath(context);
//    }else{
//        CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
//        CGContextFillRect(context, rect);
//    }
//}

//- (void)setImage:(UIImage *)image
//{
//    _image = image;
//    [self setNeedsDisplay];
//}

- (void)setName:(NSString *)name
{
    _name = name;
    lbl.text = name;
}
- (void)setIsHiddenName:(BOOL)isHiddenName
{
    _isHiddenName = isHiddenName;
    lbl.hidden = isHiddenName;
}
- (void)setImage:(UIImage *)image
{
    [super setImage:image];
    if (!image) {
        self.hidden = YES;
    }else{
        self.hidden = NO;
    }
}

@end
